'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 查询单笔充值活动信息 
 * @author agl
 */

var _ = require('lodash');
var async = require('async');
var Code = require('../../../../consts/code');
var PlayerManager = require('../../../../libs/playerManager');
var dataApi = require('../../../../libs/dataApi.js');
var payConf = require('../../../../config/payConf');
var configUtil = require('../../../../util/configUtil.js');
var constantUtil = require('../../../../util/constantUtil.js');

module.exports = function (msg, session, next) {
    var role_id = session.uid;

    var single_pay_conf = {};
    var player_manager = new PlayerManager(role_id);
    var start_time = configUtil.getOpenGameTime();
    var end_time = start_time + constantUtil.value('open_service_time') * configUtil.second_per_day;
    async.series(
        [
            function (cb) {
                player_manager.refreshData(cb);
            },
            function (cb) {
                player_manager.getModel(['role', 'pay', 'accrued'], cb);
            },
            function (cb) {
                var role_model = player_manager.role;
                var pay_model = player_manager.pay;
                var can_pay = 1;
                var next_single_pay = pay_model.next_single_pay;

                if (next_single_pay > 10000000) {
                    can_pay = 0;
                    next_single_pay -= 10000000;
                }
                single_pay_conf = dataApi.one_time_box_price.find({
                    id: next_single_pay
                });

                single_pay_conf.status = can_pay;
                single_pay_conf.reward_list = payConf.getSinglePayReward(single_pay_conf.id);

                cb();
            }
        ],
        function (err) {
            if (!!err) {
                console.error(err);
                return next(null, {
                    code: Code.FAIL
                });
            }
            return next(null, {
                code: Code.OK,
                result: {
                    start_time: start_time,
                    end_time: end_time,
                    price: single_pay_conf.id,
                    status: single_pay_conf.status,
                    reward_list: single_pay_conf.reward_list
                }
            });
        }
    );
};
